# 定义图中的节点
class Node():
    def __init__(self, name, type, index, neighbors):  # 节点名称、类型('w'为单词、'd'为文档)、编号、边
        self.name = name
        self.type = type
        self.index = index
        self.neighbors = neighbors  # 邻接节点集

    # 给节点增加边
    def add_neighbor(self, neighbor):
        if self.neighbors is None:
            self.neighbors = []

        self.neighbors.append(neighbor)


# 定义边的结构
class Edge():
    def __init__(self, node1, node2, weight):  # 节点1， 节点2， 边的权重
        self.node1 = node1
        self.node2 = node2
        self.weight = weight

    # 更新边的权重
    def update_weight(self, new_weight):
        self.weight = new_weight


# 定义图的结构
class Graph():
    def __init__(self, nodes, edges):  # 节点集， 边集
        self.nodes = nodes
        self.edges = edges
